/*
 * Copyright 2003,2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package eu.jakubiak.jpa.translator.provider.entities;

import eu.jakubiak.jpa.translator.TranslationKey;
import java.io.Serializable;
import java.util.Locale;
import javax.persistence.Embeddable;

/**
 *
 * @author Antek
 */
@Embeddable
public class TranslationId implements Serializable {
    private static final long serialVersionUID = 740233588519758936L;

    private String className;
    private String fieldName;
    private Long discriminatorValue;
    private String originalSerializedValue;
    
    private Locale locale;
    

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public Long getDiscriminatorValue() {
        return discriminatorValue;
    }

    public void setDiscriminatorValue(Long discriminatorValue) {
        this.discriminatorValue = discriminatorValue;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getOriginalSerializedValue() {
        return originalSerializedValue;
    }

    public void setOriginalSerializedValue(String originalSerializedValue) {
        this.originalSerializedValue = originalSerializedValue;
    }

    public Locale getLocale() {
        return locale;
    }

    public void setLocale(Locale locale) {
        this.locale = locale;
    }

    
    

    public TranslationId() {
    }

    
    
    public TranslationId(TranslationKey key) {
        setClassName(key.getClassName());
        setDiscriminatorValue(key.getDiscriminator());
        setFieldName(key.getFieldName());
        setOriginalSerializedValue(key.getText());
        setLocale(key.getLocale());
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final TranslationId other = (TranslationId) obj;
        if (this.className != other.className && (this.className == null || !this.className.equals(other.className))) {
            return false;
        }
        if (this.fieldName != other.fieldName && (this.fieldName == null || !this.fieldName.equals(other.fieldName))) {
            return false;
        }
        if (this.discriminatorValue != other.discriminatorValue && (this.discriminatorValue == null || !this.discriminatorValue.equals(other.discriminatorValue))) {
            return false;
        }
        if (this.originalSerializedValue != other.originalSerializedValue && (this.originalSerializedValue == null || !this.originalSerializedValue.equals(other.originalSerializedValue))) {
            return false;
        }
        if (this.locale != other.locale && (this.locale == null || !this.locale.equals(other.locale))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 97 * hash + (this.className != null ? this.className.hashCode() : 0);
        hash = 97 * hash + (this.fieldName != null ? this.fieldName.hashCode() : 0);
        hash = 97 * hash + (this.discriminatorValue != null ? this.discriminatorValue.hashCode() : 0);
        return hash;
    }
    
    
}
